package pers.cz.chat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.cz.chat.filter.CreateGroupFilter;
import pers.cz.chat.filter.LoginFilter;
import pers.cz.chat.filter.RegistFilter;
import pers.cz.chat.filter.ShowUsersFilter;
import pers.cz.jefconfig.config.JefConfiguration;
import pers.cz.netty.TcpNettyServer;
import pers.cz.netty.UdpNettyServer;
import pers.cz.netty.config.ServerNettyConfigItem;
import pers.cz.netty.filter.IFilter;
import pers.cz.netty.filter.Pipeline;

/**
 * @program: Jef-Chat
 * @description:
 * @author: Cheng Zhi
 * @create: 2024-12-15 20:00
 **/
public class ServerApplication {
    static {
        System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "error");
    }
    private static final Logger logger = LoggerFactory.getLogger(ServerApplication.class);

    public static void main(String[] args) {
        int port = JefConfiguration.getInt(ServerNettyConfigItem.SERVER_PORT, 4567);
	    logger.info("当前使用端口：{}", port);

        MessageForwardHandle messageHandle = new MessageForwardHandle();

        IFilter pipeline = new Pipeline()
                .addLast(new RegistFilter())
                .addLast(new LoginFilter())
                .addLast(new ShowUsersFilter())
                .addLast(new CreateGroupFilter());
        messageHandle.setFilter(pipeline);
        // 启动服务
        if ("UDP".equalsIgnoreCase(JefConfiguration.get(ServerNettyConfigItem.SERVER_COMM_TYPE, "TCP"))) {
            new UdpNettyServer(port).start(messageHandle);
        } else {
            new TcpNettyServer(port).start(messageHandle);
        }
    }
}
